<!--
/**************************************************
* @(#)checkManufacture.jsp
*
* Copyright (c) 2005 Hitrust Technology Inc.
* Developed by SDC, Hitrust.
* All Rights Reserved.
*
* Modify History:
*  v1.00, 2006/02/08, SimonyiPeng
*  1) first release
/**************************************************
-->

<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ page import="com.hitrust.gs.business.GSManufactureProcessor"%>
<%@ page import="com.hitrust.gs.bean.GSManufactureBean"%>
<%@ include file="../../common.jsp" %>
<SCRIPT language="JavaScript" src="<%=root%>/js/common.js"></SCRIPT>
<SCRIPT language="JavaScript" src="<%=root%>/js/string.js"></SCRIPT>


<%
//System.out.println("1111x");

boolean isManufactureExist = false;
GSManufactureBean bean = null;
String rowNum = request.getParameter("rownum");
System.out.println(rowNum);
String concentricityId = request.getParameter("concentricityid");
String providerId = request.getParameter("providerid");
//System.out.println("providerid"+providerId);
GSManufactureProcessor processor = new GSManufactureProcessor ();
GSManufactureBean tBean = processor.getManufactureForOrderInput(concentricityId);
ArrayList provList = null;
if(providerId != null && !"".equals(providerId) && !rowNum.equals("1") ){
provList = processor.getProviderSimpleByconcentricityidWithProvider(concentricityId,providerId);
}else{
provList = processor.getProviderSimpleByconcentricityid(concentricityId);
}

String manufactureId = null;
String manufactureName = null;
String quantUnit = null;
String manufactureUnitPrice = null;
String spec = null;
String type = null;
String brand = null;
String quantunit = null;
String period = null;
String mode=null;
boolean bool = false;

if(tBean != null && provList != null && provList.size() != 0){

	concentricityId = tBean.getGs_concentricity();
	manufactureName = tBean.getGs_manufacture_name();
	quantUnit = tBean.getGs_quant_unit();
	manufactureUnitPrice = StringUtils.formatEDouble(tBean.getGs_manufacture_unitprice(),4);
	spec = StringUtils.escapeXML(tBean.getGs_manufacture_spec());
	type = tBean.getGs_manufacture_type();
	quantunit = tBean.getGs_quant_unit();
	brand = tBean.getGs_manufacture_brand();
    mode=tBean.getGs_balance_mode();
	
	bool = true;
}
%>

<html>
<body onLoad="onsubmit();"></body>
<script language='javascript'>	
	function onsubmit(){

		if(<%=bool%>){

			
			var provId;	
			var provShortName;
			var concentricityId;
			var manufactureId;
			var unitPrice;
            var balancemode;
            var s;
			if(<%=rowNum%>=='1'){//如果是第1行
				var providerlist = parent.document.getElementById("providerid");
				var price1buffer = "";
			<%
				for(int x=0;x<provList.size();x++){
			%>
					provId = "<%=((String[])provList.get(x))[0]%>";
					provShortName = "<%=((String[])provList.get(x))[1]%>";
					concentricityId = "<%=((String[])provList.get(x))[2]%>";
					manufactureId = "<%=((String[])provList.get(x))[3]%>";
					unitPrice = "<%=((String[])provList.get(x))[4]%>";
                    balancemode = "<%=((String[])provList.get(x))[5]%>";
                    if(balancemode=='<%=GSBaseConstants.BALANCE_MODE1%>'){
                        s="<%=DefineDic.getBalanceMode(GSBaseConstants.BALANCE_MODE1)%>";
                    }else{
                        s="<%=DefineDic.getBalanceMode(GSBaseConstants.BALANCE_MODE2)%>";
                    }
					parent.document.getElementById("manufactureid1").value = manufactureId;
					//parent.location="javascript:initprovider("+<%=x%>+",'"+provShortName+"','"+provId+"');";
					var provid = parent.document.getElementById("providerid");
					var tempoption=new Option(provShortName,provId);
					provid.options[provid.length] = tempoption;					
					price1buffer = price1buffer + provId + ":" + unitPrice + ":" + concentricityId + ":" + manufactureId +":"+balancemode+":"+s+ "|";
			<%
				}
			%>
				parent.document.getElementById("price1buffer").value = price1buffer;
			}else{//如果是第2-10行
				var providerid = parent.document.getElementById("providerid").value;
                
				if(providerid == "" || providerid == null){
					alert("请先选择供应商");
					return false;
				}
				if(providerid != "" && providerid != null){
                
						var isProvExist = false;
						<%
							for(int x=0;x<provList.size();x++){
						%>
								provId = "<%=((String[])provList.get(x))[0]%>";
								provShortName = "<%=((String[])provList.get(x))[1]%>";
								if(provId == providerid){
									isProvExist = true;
									concentricityId = "<%=((String[])provList.get(x))[2]%>";
									manufactureId = "<%=((String[])provList.get(x))[3]%>";
									unitPrice = "<%=((String[])provList.get(x))[4]%>";
                                    balancemode="<%=((String[])provList.get(x))[5]%>";
                                    if(balancemode=='<%=GSBaseConstants.BALANCE_MODE1%>'){
                                        s="<%=DefineDic.getBalanceMode(GSBaseConstants.BALANCE_MODE1)%>";
                                    }else{
                                        s="<%=DefineDic.getBalanceMode(GSBaseConstants.BALANCE_MODE2)%>";
                                    }
									parent.document.getElementById("manufactureid"+<%=rowNum%>).value = manufactureId;
								}
						<%
							}
						%>
						if(isProvExist){
							parent.document.getElementById("providerid"+<%=rowNum%>).innerHTML="<div align='center' class='txt_content'>"+provShortName+"</div>";
							parent.document.getElementById("signinprice"+<%=rowNum%>).value=unitPrice;
							parent.document.getElementById("referenceprice"+<%=rowNum%>).value=unitPrice;
							parent.document.getElementById("manufactureid"+<%=rowNum%>).value=manufactureId;
							parent.document.getElementById("mode"+<%=rowNum%>).value=balancemode;
                            parent.document.getElementById("divmode"+<%=rowNum%>).innerText=s;
						}else{
							parent.document.getElementById("providerid"+<%=rowNum%>).innerHTML="<div align='center' class='txt_content'></div>";
							alert("您录入的集中编码不在指定供应商的产品列表中，请重新录入");
							return false;
						}

				}					
			}
			
			<%
			if (GSSystemConfigurator.getParam("gs.SetManufactureCode13").equalsIgnoreCase("true"))
			{
			%>
				parent.document.getElementById("concentricityid"+<%=rowNum%>).value = concentricityId;
				parent.document.getElementById("concentricityid_"+<%=rowNum%>).value = concentricityId;	
			<%
			}
			else
			{
			%>
				parent.document.getElementById("concentricityid"+<%=rowNum%>).value = '<%=concentricityId%>';
				parent.document.getElementById("concentricityid_"+<%=rowNum%>).value = '<%=concentricityId%>';	
			<%
			}
			%>	
			if("1601" == parent.document.getElementById("currmenu").value){
				parent.document.getElementById("manufacturename"+<%=rowNum%>).innerHTML="<div align='center' class='txt_content'><a href='<%=response.encodeURL(root+"/A160103.do")%>?concentricityId="+"<%=concentricityId%>"+"' target='_blank'>"+"<%=manufactureName%>"+"</a></div>";
			}else if("1101" == parent.document.getElementById("currmenu").value){
				parent.document.getElementById("manufacturename"+<%=rowNum%>).innerHTML="<div align='center' class='txt_content'><a href='<%=response.encodeURL(root+"/A110104.do")%>?concentricityId="+"<%=concentricityId%>"+"' target='_blank'>"+"<%=manufactureName%>"+"</a></div>";
			}

			parent.document.getElementById("spec"+<%=rowNum%>).innerHTML = "<div align='center' class='txt_content'>"+'<%=spec%>'+"</div>";
			parent.document.getElementById("type"+<%=rowNum%>).innerHTML = "<div align='center' class='txt_content'>"+'<%=type%>'+"</div>";
			parent.document.getElementById("brand"+<%=rowNum%>).innerHTML = "<div align='center' class='txt_content'>"+'<%=brand%>'+"</div>";
			parent.document.getElementById("quantunit"+<%=rowNum%>).innerHTML = "<div align='center' class='txt_content'>"+'<%=quantunit%>'+"</div>";

			//为确认提示预备值
			if(parent.document.getElementById("manufacturename_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturename_"+<%=rowNum%>).value = "<%=manufactureName%>";
			if(parent.document.getElementById("manufacturespec_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturespec_"+<%=rowNum%>).value = "<%=spec%>";
			if(parent.document.getElementById("manufacturetype_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturetype_"+<%=rowNum%>).value = "<%=type%>";
			if(parent.document.getElementById("manufacturebrand_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturebrand_"+<%=rowNum%>).value = "<%=brand%>";
			if(parent.document.getElementById("manufacturequantunit_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturequantunit_"+<%=rowNum%>).value = "<%=quantunit%>";

		}
		else{
			parent.document.getElementById("concentricityid"+<%=rowNum%>).value = '';
			parent.document.getElementById("concentricityid_"+<%=rowNum%>).value = '';
			parent.document.getElementById("manufacturename"+<%=rowNum%>).innerHTML = '';

			parent.document.getElementById("spec"+<%=rowNum%>).innerHTML = '';
			parent.document.getElementById("type"+<%=rowNum%>).innerHTML = '';
			parent.document.getElementById("brand"+<%=rowNum%>).innerHTML = '';
			parent.document.getElementById("quantunit"+<%=rowNum%>).innerHTML = '';

			//为确认提示清理预备值
			if(parent.document.getElementById("manufacturename_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturename_"+<%=rowNum%>).value = "";
			if(parent.document.getElementById("manufacturespec_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturespec_"+<%=rowNum%>).value = "";
			if(parent.document.getElementById("manufacturetype_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturetype_"+<%=rowNum%>).value = "";
			if(parent.document.getElementById("manufacturebrand_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturebrand_"+<%=rowNum%>).value = "";
			if(parent.document.getElementById("manufacturequantunit_"+<%=rowNum%>)!=null)
				parent.document.getElementById("manufacturequantunit_"+<%=rowNum%>).value = "";
						
			alert("集中编码输入不正确！");
		}

		return  false;
	}
</script>
</html>


